package com.dataextend.service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by ApacheMoy on 2020/4/15.
 */
public class ReponseTrace {
    private String name;
    private String certificateId;
    private String traceTime;
    private String photo;

    public ReponseTrace() {
    }

    public ReponseTrace(String name, String certificateId, String traceTime, String photo) {
        this.name = name;
        this.certificateId = certificateId;
        this.traceTime = traceTime;
        this.photo = photo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCertificateId() {
        return certificateId;
    }

    public void setCertificateId(String certificateId) {
        this.certificateId = certificateId;
    }

    public String getTraceTime() {
        return traceTime;
    }

    public void setTraceTime(String traceTime) {
        this.traceTime = traceTime;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    @Override
    public String toString() {
        return "ReponseTrace{" +
                "name='" + name + '\'' +
                ", certificateId='" + certificateId + '\'' +
                ", traceTime='" + traceTime + '\'' +
                ", photo='" + photo + '\'' +
                '}';
    }

    /**
     * 2ȥ��
     */
    public static List<ReponseTrace> removeDupliByRecordId(List<ReponseTrace> reponseTraces) {
        Set<ReponseTrace> personSet = new TreeSet<ReponseTrace>((o1, o2) -> Long.valueOf(o1.getCertificateId()).compareTo(Long.valueOf(o2.getCertificateId())));
        personSet.addAll(reponseTraces);
        return new ArrayList<ReponseTrace>(personSet);
    }

    /**
     *
     * @param
     */
    public static List<ReponseTrace> sort(List<ReponseTrace> reponseTraces) {
        DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Collections.sort(reponseTraces, new Comparator<ReponseTrace>() {

            @Override
            public int compare(ReponseTrace o1, ReponseTrace o2) {
                return o2.getTraceTime().compareTo(o1.getTraceTime());
            }
        });
        return reponseTraces;
    }


    public static void main(String[] args) {
        List<ReponseTrace> list = new ArrayList<>();
        ReponseTrace a = new ReponseTrace("a", "5", "2020-04-01 12:00:00", "aphoto");
        ReponseTrace b = new ReponseTrace("b", "4", "2020-03-15 12:00:00", "bphoto");
        ReponseTrace c = new ReponseTrace("c", "9", "2020-03-22 12:00:00", "cphoto");
        ReponseTrace d = new ReponseTrace("d", "5", "2020-04-05 12:00:00", "dphoto");
        ReponseTrace e = new ReponseTrace("d", "5", "2020-04-06 12:00:00", "dphoto");
        ReponseTrace f = new ReponseTrace("d", "5", "2019-12-05 12:00:00", "dphoto");
        list.add(a);
        list.add(b);
        list.add(c);
        list.add(d);
        list=sort(list);
        List<ReponseTrace> result = removeDupliByRecordId(list);
        for (ReponseTrace reponseTrace : result) {
            System.out.println(reponseTrace);
        }


        String tagid = "A112_03_001";
        System.out.println("  tagid:" + tagid + "    tagid_:" + tagid.substring(0,7));
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        System.out.println(formatter.format(date));


        Random r = new Random();
        int i1 = r.nextInt(200) + 2000; // 生成[0,10]区间的整数
        System.out.println("-----------------------i1:" + i1);


        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            long startDate_ = simpleDateFormat.parse("2020-11-15 15:00:00").getTime();
            String startDate = "2020-11-15 15:00:00".substring(0,10);
            String endDate = simpleDateFormat.format(new Date(startDate_ + 86400000*3));
            System.out.println("-----------------------startDate:" + startDate + "  endDate:" + endDate);

        }catch (Exception e1){
            e1.printStackTrace();
        }


        String aa = "石家庄,A112_08_001";
        System.out.println("aaaaaaaaaaaaaaaaaaaa:" + aa.contains("_"));


    }

}
